home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Join.rexx 1.2 - 01-Apr-97 by Kai.Nikulainen@utu.fi
- **
- ** Joins and uudecodes messages from ftp-mailservers. The problem with this
- ** script is there are almost as many formats of messages as there are servers.
- ** So, if you are having problems with your server send me mail and I'll try
- ** to fix the problem.
- **
- ** This script only decodes uuencoded files now. Base64 coding will be added
- ** if there are requests for it. I have tested the script with following servers
- ** (which all have different message formats...)
- ** -mailserver@nic.funet.fi
- ** -mailserver@leo.org
- ** -ftp-mail@uni-paderborn.de
- ** -Anything mailed with SplitNMail.rexx should work
- **
- ** Send a message to any of the above addresses with word HELP in message body and
- ** you will receive instructions on how to use them.
- **
- ** Installation:
- ** - Copy the script to yam:rexx
- ** - Check that variables tempfile, uudecode and del_temp have suitable values.
- ** Especially uudecode may need to be changed, depending on which uudecoder
- ** you are using.
- **
- ** Usage:
- ** - Just select a message and start the script. The script will find all messages
- ** in the current folder from the same sender with almost the same subject, sort
- ** them and write the uucoded part to a file and then execute the uudecode command
- ** - If something goes wrong, check t:uu.log for a possible explanation.
- **
- ** Send all comments, bug reports, suggestions and X-mas cards to knikulai@utu.fi
- */
-
- options results
- call addlib('rexxsupport.library',0,-30)
- call addlib('rexxreqtools.library',0,-30)
-
- tempfile='t:join.tmp' /* All parts are joined to this file */
- uudecode='c:uudecode >>t:uu.log' tempfile 'path work:home/'
- del_temp='YES' /* set to yes, if you want to delete the joined ASCII file */
-
- startline.1='BEGIN -----'
- stopline.1='END -----'
- startline.2='BEGIN PART'
- stopline.2='END PART'
- startline.3='begin '
- stopline.3='include '
- delimiters=3
-
- title='Join.rexx'
- txt='Found the following files in this order:'
- buts='_Join them|_Quit'
-
- mc=0
- used=0
-
- address 'YAM'
- 'GetMailInfo From'
- server=result
- 'GetMailInfo Subject'
- subj=result
- 'GetMailInfo Active'
- active=result
- 'GetFolderInfo Max'
- n=result
-
- /*
- ** First scan all messages in the folder.
- ** Search for messages with same sender and at most 4 different chars in subject
- */
-
- do m=0 to n-1
- 'SetMail' m
- 'GetMailInfo From'
- if result=server then do
- 'GetMailInfo Subject'
- if SubDiff(result,subj)<5 then call AddMsg(result)
- end /* if result=server then do */
- end /* do m=1 to n */
- 'SetMail' active
- /*
- ** Then sort the messages. Hopefully part 10 comes after 9 and not after 1....
- */
-
- call SortMessages
-
- do i=1 to mc
- txt=txt || '0a'x || strip(left(subject.i,70))
- end
- sel=rtezrequest(txt,buts,title,'rtez_defaultresponse=1')
- if sel=0 then exit
-
- /*
- ** Lets write the messages into one file
- */
- if open(tmp,tempfile,'w') then do
- do i=1 to mc
- call open(1,filename.i,'r')
- if findstart() then do
- find_end=0
- /*
- ** Next copy lines to tempfile until the end of file,
- ** stopline is found or an empty line. The last line is
- ** not written to the tempfile.
- */
- do until find_end | eof(1) | rivi=''
- rivi=readln(1)
- find_end=pos(stopline.used,rivi)=1
- if find_end=0 then call writeln(tmp,rivi)
- end /* do until */
- end /* if FindStart then */
- else do
- /*
- ** There should not be need to read every part twice, but I'm
- ** supposing someone did the posting manually and the start
- ** and stoplines were left out by mistake from some parts.
- ** Reading the message avoids screwing things up if some
- ** parts have delimiters and some doesn't.
- */
- call close(1)
- call open(1,filename.i,'r') /* Let's try again with better luck... */
- rivi=readln(1)
- /* Find first empty line */
- do until rivi='' | eof(1)
- rivi=readln(1)
- end
- /* Find first non blank line */
- do until rivi~='' | eof(1)
- rivi=readln(1)
- end
- /* Copy lines until the next blank line */
- do until rivi='' | eof(1)
- call writeln(tmp,rivi)
- rivi=readln(1)
- end
- end /* else */
- call close(1)
- end /* do i=1 to mc */
- end /* if open(*/
- else
- 'Request "Can not open' tempfile '" "_Ok"'
-
- 'SetMail' active /* Go back to the originally selected message */
- call writeln(tmp,'end')
- call close(tmp) /* File must be closed before it can be read */
- address command uudecode /* Do some magic */
-
- if upper(del_temp)='YES' then delete(tempfile)
-
- address 'YAM' 'Request " All done! " "_Ok"'
- exit /* It's the end of the script as we know it... */
-
- FindStart:
- found_it=0
- if used=0 then do
- /*
- ** When called the first time, this branch checks which delimiters are used
- ** Following calls use else branch
- */
- do until eof(1) | found_it
- rivi=readln(1)
- do d=1 to delimiters
- if pos(startline.d,rivi)=1 then do
- found_it=1
- used=d
- end /* if */
- end /* do d=1 */
- end /*do until */
- if used=3 then call writeln(tmp,rivi) /* Save uuencode first line */
- end /* ifused=0 */
- else do
- do until eof(1) | found_it
- rivi=readln(1)
- found_it=pos(startline.used,rivi)
- end /*do until */
- end /* else do */
- return found_it
-
- SubDiff: procedure
- /* Differences between strings are calculate by word */
- parse arg s1,s2
- diff=0
- do i=1 to words(s1)
- diff=diff+ChrDiff( word(s1,i) , word(s2,i) )
- end
- return diff
-
- ChrDiff: procedure
- parse arg s1,s2
- if length(s1)+1=length(s2) then s1='0's1
- if length(s1)-1=length(s2) then s2='0's2
- diff=abs(length(s1)-length(s2))
- do i=1 to length(s1)
- if substr(s1,i,1)~=substr(s2,i,1) then diff=diff+1
- end
- return diff
-
- AddMsg:
- /*
- ** This changes the subject's 'part n' to 'part 0n' to allow sorting
- */
- parse arg s
- mc=mc+1
- l=pos('part ',s)
- if l>0 then
- subject.mc=left(s,l-1) || 'part 0' || substr(s,l+5)
- else
- subject.mc=s
- 'GetMailInfo File'
- filename.mc=result
- return
-
- SortMessages:
- /*
- ** A simple algorithm is fastest with relatively few items.
- ** There should be no need for something fancy like quicksort :-)
- */
- do i=2 to mc
- do j=1 to i-1
- if subject.j>subject.i then do/* let's swap stuff... */
- temp=subject.j
- subject.j=subject.i
- subject.i=temp
- temp=filename.j
- filename.j=filename.i
- filename.i=temp
- end /* if */
- end /* do j */
- end /* do i */
- return /* Everything should be in order now... */
-